package com.landian.commons.jpa.criteria;

import com.querydsl.core.types.Path;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * PredicableFactory
 * @author caojl
 * @create 2017/11/30
 **/
public class PredicableFactory {

    /**
     * equal
     * @param dslPath
     * @param value
     * @return
     */
    public static Predicable equal(Path<?> dslPath, Object value){
        return EqualPredicable.newInstance(dslPath,value);
    }

    /**
     * in
     * @param dslPath
     * @param collection
     * @return
     */
    public static Predicable in(Path<?> dslPath, Collection collection){
        return InPredicable.newInstance(dslPath,collection);
    }

    /**
     * like
     * @param dslPath
     * @param value
     * @return
     */
    public static Predicable like(Path<?> dslPath, String value){
        return LikePredicable.newInstance(dslPath,value);
    }

    /**
     * or
     * @param predicableArr
     * @return
     */
    public static Predicable or(Predicable... predicableArr){
        return OrPredicable.newInstance(predicableArr);
    }

    /**
     * or
     * @param predicableList
     * @return
     */
    public static Predicable or(List<Predicable> predicableList){
        Predicable[] predicableArr = predicableList.toArray(new Predicable[predicableList.size()]);
        return OrPredicable.newInstance(predicableArr);
    }

    /**
     * and
     * @param predicableArr
     * @return
     */
    public static Predicable and(Predicable... predicableArr){
        return AndPredicable.newInstance(predicableArr);
    }

    /**
     * and
     * @param predicableList
     * @return
     */
    public static Predicable and(List<Predicable> predicableList){
        Predicable[] predicableArr = predicableList.toArray(new Predicable[predicableList.size()]);
        return AndPredicable.newInstance(predicableArr);
    }

    /**
     * ge
     * @param dslPath
     * @param date
     * @return
     */
    public static Predicable ge(Path<?> dslPath, Date date){
        return GePredicable.newInstance(dslPath,date);
    }

    /**
     * le
     * @param dslPath
     * @param date
     * @return
     */
    public static Predicable le(Path<?> dslPath, Date date){
        return LePredicable.newInstance(dslPath,date);
    }

    /**
     * isNull
     * @param dslPath
     * @return
     */
    public static Predicable isNull(Path<?> dslPath){
        return NullPredicable.newInstance(dslPath);
    }

    /**
     * 关键字Predicable
     * @param keyWord
     * @return
     */
    public static Predicable keyWord(String keyWord, com.querydsl.core.types.Path<?>... dslPaths) {
        if(StringUtils.isBlank(keyWord)){
            return null;
        }
        return KeyWordPredicable.newInstance(keyWord,dslPaths);
    }
}